package com.example.demo.web;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class BaseController {
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    private UserService userService;
    @RequestMapping("/singup")
    public JSONObject singup(User user){
        user.setUserPassword(bCryptPasswordEncoder.encode(user.getUserPassword()));
        boolean flag=userService.insert(user);
        JSONObject jsonObject = new JSONObject();
        if (flag){
            jsonObject.put("code",200);
            jsonObject.put("msg","注册成功");
        }else {
            jsonObject.put("code",401);
            jsonObject.put("msg","fail");
        }
        return jsonObject;
    }
}
